﻿using Map;
using Map_Creator.MapInfo;
using Microsoft.Xna.Framework;

namespace Map_Creator.RedoUndo.Actions
{
    class AnimatedTileChange : IAction
    {
        private AnimatedTile newAnimatedTile;
        private int destTileSetID;
        private Point destPosition;
        private AnimatedTile oldAnimatedTile;

        public AnimatedTileChange(AnimatedTile newAnimatedTile, TileSet tileSet, Point destPosition)
        {
            this.newAnimatedTile = newAnimatedTile;
            destTileSetID = tileSet.ID;
            this.destPosition = destPosition;
            oldAnimatedTile = (AnimatedTile) tileSet.DefinedAnimatedTiles[destPosition];
        }

        public void Do()
        {
            var tileSet = ((TileSet)BaseObject.Objects[destTileSetID]);
            tileSet.DefinedAnimatedTiles[destPosition] = newAnimatedTile;
        }

        public void Undo()
        {
            var tileSet = ((TileSet)BaseObject.Objects[destTileSetID]);
            tileSet.DefinedAnimatedTiles[destPosition] = oldAnimatedTile;
        }

        public string GetDescription()
        {
            return "Change Animated Tile At : " + destPosition.X + ", " + destPosition.Y;
        }

        public string GetName()
        {
            return "Change Animated Tile";
        }
    }
}